﻿<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Favorite.aspx.cs" Inherits="LabMS.Web.Resource.Favorite" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>我的收藏</title>
    <link type="text/css" rel="stylesheet" href="../style/screen.css" />
    <!--[if lte IE 6]>
    <link type="text/css" rel="stylesheet" href="../style/ie6.css" />
    <![endif]-->
    <!--[if lte IE 7]>
    <link type="text/css" rel="stylesheet" href="../style/ie7.css" />
    <![endif]-->
</head>
<body class="mainBody">
    <form id="form1" runat="server">
        <div class="main">
            <div id="pageInfo" class="clearfix">
                <div class="title">
                    <label>
                        我收藏的资源</label>
                </div>
            </div>
        </div>
        <div class="main">
            <p>
                <asp:Button ID="BtnDelete" Enabled="false" CssClass="button" runat="server" Text="删除"
                    OnClick="BtnDelete_Click" />
                <input type="button" value="刷新" class="button" id="refresh" />
            </p>
            <%--<p>
                <asp:DropDownList ID="SearchCondition" runat="server">
                    <asp:ListItem Value="1" Text="按标题搜索"></asp:ListItem>
                    <asp:ListItem Value="2" Text="按关键字搜索"></asp:ListItem>
                </asp:DropDownList><asp:TextBox ID="SearchText" runat="server"></asp:TextBox>
                <asp:Button ID="BtnSearch" CssClass="button" runat="server" Text="搜索" Enabled="false"
                    OnClick="BtnSearch_Click" />
            </p>--%>
        </div>
        <div class="main">
            <asp:GridView ID="GridViewResourceList" DataKeyNames="id" runat="server" AutoGenerateColumns="False"
                CssClass="infoTable" Width="100%" AllowPaging="True" PageSize="10" OnPageIndexChanging="GridViewResourceList_PageIndexChanging">
                <Columns>
                    <asp:TemplateField ItemStyle-CssClass="checkBox">
                        <HeaderTemplate>
                            <asp:CheckBox ID="CBAll" runat="server" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="CBSelect" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="id" ShowHeader="False" ItemStyle-CssClass="none" HeaderStyle-CssClass="none" />
                    <asp:BoundField DataField="ResourceTitle" HeaderText="标题" />
                    <asp:BoundField DataField="LabName" HeaderText="所属实验室" />
                    <asp:BoundField DataField="RecorderName" HeaderText="发布人" />
                    <asp:BoundField DataField="ResourceRecordTime" HeaderText="发布时间" DataFormatString="{0:yyyy/MM/dd}" />
                    <asp:BoundField DataField="ResourceVisitTime" HeaderText="访问统计" />
                    <asp:HyperLinkField Target="_blank" DataNavigateUrlFields="AttatchmentPath" Text="下载附件" />
                </Columns>
                <EmptyDataTemplate>
                    暂无相关数据
                </EmptyDataTemplate>
                <HeaderStyle CssClass="header" />
                <PagerSettings FirstPageText="首页" LastPageText="最后页" NextPageText="后一页" PreviousPageText="前一页"
                    Mode="NextPreviousFirstLast" />
            </asp:GridView>
        </div>
    </form>
    <script type="text/javascript" src="../js/jQuery/jquery-1.3.1.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.tooltip.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.bgiframe.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.validate.js"></script>

    <script type="text/javascript" src="../js/site.js"></script>

    <script type="text/javascript">

        $(function(){
            /* 修改样式 */
            $("#GridViewResourceList > tbody > tr:even").not(":first").addClass("even");
            $("#GridViewResourceList > tbody > tr").not(":first")
                .hover(
                    function(){
                        $(this).addClass("hover");
                    },
                    function(){
                        $(this).removeClass("hover");
                })
                .dblclick(function(e){
                    if ($(this).find("td:nth-child(2)").attr("className") == "none") {
                        var id = $(this).find("td:nth-child(2)").html();
                        openWin("Detail.aspx?id=" + id);
                    }
                });

            /* 全选 */
            $("#GridViewResourceList > tbody > tr:first :checkbox").click(function(){
                if ($(this).attr("checked")){
                    $("#GridViewResourceList :checkbox").attr("checked", "checked");
                    cbChanged();
                } else{
                    $("#GridViewResourceList :checkbox").attr("checked", "");
                    cbChanged();
                }
            });

            /* Checkbox事件 */
            $("#GridViewResourceList :checkbox").not(":first").click(cbChanged);

            /* 设置链接 */
            $("a").each(function(event){
                var url = $(this).attr("href");
                if (typeof(url) != 'undefined' && url != '') {
                    if ($(this).attr("target") == '_blank') {
                        $(this).click(function(e){
                            openUrl(url);
                            e.preventDefault();
                        });
                    }
                } else {
                    $(this).addClass("disabled");
                }
            });

            $("#BtnDelete").click(function(e){
                if (!confirm('您确认要删除所选收藏?')) {
                    e.preventDefault();
                }
            });

            cbChanged();

            $("#SearchText").keyup(function(){
                if ($(this).val().length > 0) {
                    $("#BtnSearch").attr("disabled", "");
                } else {
                    $("#BtnSearch").attr("disabled", "disabled");
                }
            });

             $("#SearchText").keyup();

             $("#refresh").click(function(){
                location.replace(location);
             });
        });

        /* 新窗口打开链接 */
        function openWin(url) {
            // return window.showModalDialog(url, window, 'dialogHeight:600px; dialogWidth:900px; center: yes; resizable: yes; scroll: yes; status: no;');
            // var newWin = window.open(url, "win", "height=600, width=800, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no");newWin.focus();
            window.location.href = url;
        }

        /* 检测Checkbox的选择状态，更改button的disabled属性 */
        function cbChanged(){
            var hasChecked = false;
            var allChecked = true;
            $("#GridViewResourceList :checkbox").not(":first").each(function(index, domEle){
                var curChecked = $(domEle).attr("checked");
                if (!hasChecked && curChecked){
                    hasChecked = true;
                }

                allChecked &= curChecked;
            });

            if (hasChecked){
                $("#BtnDelete,#BtnAddToFavorite").attr("disabled", "");
            } else {
                $("#BtnDelete,#BtnAddToFavorite").attr("disabled", "disabled");
            }

            if (allChecked){
                $("#GridViewResourceList :checkbox").filter(":first").attr("checked", "checked");
            } else {
                $("#GridViewResourceList :checkbox").filter(":first").attr("checked", "");
            }
        }

    </script>
</body>
</html>
